const mongodb = require('mongodb');
const mongClient = mongodb.MongoClient;
const ObjectId = mongodb.ObjectId

exports.ObjectId = ObjectId;

var url = 'mongodb://localhost:27017/knowErr';


function getDB(callback) {
    //真正的连接数据库
    MongoClient.connect(url, function (err, db) {
        callback(err, db)
    })
}


// 查询一条数据
exports.findOne = (collectionName,condition,callback) => {
    mongClient.connect(url,function(err,db){
        // 获取集合
        let collection = db.collection(collectionName)
        console.log(collection, 5656565656)
        collection.findOne(condition,(err,doc) => {
          
            callback(err,doc)
        })
        db.close();
    })
}
